<template>
  <div class="week-plan-item">
    <div class="title">
      {{ plan.year }}-{{ plan.gmtMonth }}第{{ plan.weekInMonth }}周
      <span>{{ weekRanges }}</span>
    </div>
    <div class="text">
      <div class="item">
        生产桥梁：<span>{{ bridgeName }}</span>
      </div>
      <div class="item">
        计划生产<span>{{ plan.sliceNum }}</span>片梁
      </div>
      <div class="item">
        边梁<span>{{ plan.edgeNum }}</span>片 中梁<span>{{ plan.middleNum }}</span>片
      </div>
    </div>
    <div class="option">
      <van-button
        plain
        type="info"
        size="small"
        @click="edit"
      >
        修改
      </van-button>
      <van-button
        plain
        type="danger"
        size="small"
        @click="remove"
      >
        删除
      </van-button>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
import { mapState } from "vuex";

export default {
  name: "PlanItem",
  props: {
    plan: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  computed: {
    ...mapState({ preData: (state) => state.pre }),
    bridgeName() {
      return this.preData.bridge.find((item) => item.id === this.plan.bridgeId)
        .bridgeName;
    },
    weekRanges() {
      let all = this.libs.week(this.plan.year);
      if (!all) return "";
      let week = all.find(
        (item) =>
          item.year === this.plan.year &&
          item.week === parseInt(this.plan.gmtMonth) &&
          item.weekInMonth === this.plan.weekInMonth
      );
      if (!week) return "";
      return (
        dayjs(week.startTime).format("YYYY/MM/DD") +
        " ~ " +
        dayjs(week.endTime).format("YYYY/MM/DD")
      );
    },
  },
  data() {
    return {};
  },
  methods: {
    edit() {
      this.$emit("edit", this.plan);
    },
    remove() {
      this.$dialog
        .confirm({
          title: "删除提示",
          message: "此操作将永久删除数据, 是否继续?",
        })
        .then(() => {
          this.$emit("remove");
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.week-plan-item {
  padding: 15px;
  .title {
    padding-left: 15px;
    font-weight: 700;
    font-size: 18px;
    line-height: 30px;
    position: relative;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    &::before {
      content: "";
      position: absolute;
      display: block;
      height: 20px;
      top: 50%;
      left: 0;
      width: 4px;
      background: #3e88e2;
      border-radius: 2px;
      margin-top: -10px;
    }
    span {
      font-size: 12px;
      font-weight: 400;
      color: #666;
    }
  }
  .item {
    margin: 5px 0;
    font-size: 14px;
    color: #999;
    span {
      color: #666;
    }
  }
  .option {
    .van-button {
      margin-right: 10px;
      padding: 0 20px;
    }
  }
}
</style>
